﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="check_out_admin.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.check_out_admin" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <%
        int id = int.Parse(Request.QueryString["id"]);

        int check_hour = DateTime.Now.Hour;
        string work_time = "Vắng";

        var get_check = new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == id).ToList();
        if (get_check.Count == 0)
        {

            new TblCheckManagerController().Insert(id, DateTime.Now, DateTime.Now, false, true, false);

            var get_manager = new TblManagerController().FetchAll().Where(x => x.ManagerId == id).Single();
            var get_role = new TblManagerRoleController().FetchAll().Where(x => x.RoleId == get_manager.Role).Single();
            var get_check_last = new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == id).Last();

            if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour <= 12)
            {
    %>
    <audio class="voice" src="../../Content/testdata/audio/Simasen.mp3" autoplay="autoplay"></audio>
    <%}
            else
            {
                if (DateTime.Now.Hour >= 13 && DateTime.Now.Hour <= 16)
                { %>
    <audio class="voice" src="../../Content/testdata/audio/Simasen.mp3" autoplay="autoplay"></audio>
    <%}
                else
                {
                    if (DateTime.Now.Hour >= 17 && DateTime.Now.Hour <= 23)
                    {
    %>
    <audio class="voice" src="../../Content/testdata/audio/Simasen.mp3" autoplay="autoplay"></audio>
    <%
                    }
                }
            }%>
    <tr class="error">
        <td colspan="4" class="w3-center w3-text-deep-orange"><i class="fa fa-frown-o"></i>&nbsp;<b>Đã xin vắng</b></td>
    </tr>
    <tr id="<%=get_check_last.Id%>" class="<%=get_manager.ManagerId%>">
        <td class="checkinout-img w3-hide-small w3-center">
            <span class="check_id w3-hide"><%=get_check_last.Id%></span>
            <img src="../Content/avatar/<%=get_manager.Avatar%>" class="w3-circle" alt="Avatar" />
        </td>
        <td>
            <span><%=get_manager.FullName %></span><br />
            <span class="w3-text-grey w3-hide-small"><%=get_role.RoleName %></span>
        </td>
        <td><%=work_time%></td>
        <%int get_id = int.Parse(Session["admin_id"].ToString());
          var check_cap = new TblManagerController().FetchAll().Where(x => x.ManagerId == get_id).Single();
          if (check_cap.Captain == true)
          { %>
        <td>
            <%if (get_check_last.Accept == false)
              {
                  if (get_check_last.CheckOut != null)
                  {%>
            <i title="Xác nhận" class="btn_confirm_check checkinout-option-btn fa fa-check w3-hover-text-teal"></i><%}
                  else
                  {%><%}
              }
              else
              { %>
            <i title="Đã xác nhận" class="checkinout-option-btn fa fa-check w3-text-teal"></i>
            <%} %>
            <i title="Chỉnh sửa" class="btn_edit_check checkinout-option-btn fa fa-wrench w3-hover-text-teal"></i>
            <i title="Xóa" class="btn_del_check checkinout-option-btn fa fa-trash w3-hover-text-teal"></i>
        </td>
        <%}
          else
          {
              if (get_check_last.Accept == true)
              {
        %>

        <td>
            <i title="Đã xác nhận" class="checkinout-option-btn fa fa-check w3-text-teal"></i>
        </td>
        <%
              }
          } %>
    </tr>
    <%
        }
        else
        {
            var get_check_last = new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == id && DateTime.Parse(x.CheckIn.ToString()).Date == DateTime.Now.Date);
            if (get_check_last.ToList().Count != 0)
            {
                int check_last = DateTime.Parse(get_check_last.Last().CheckIn.ToString()).Hour;

            }
            new TblCheckManagerController().Insert(id, DateTime.Now, DateTime.Now, false, true, false);

            var get_manager = new TblManagerController().FetchAll().Where(x => x.ManagerId == id).Single();
            var get_role = new TblManagerRoleController().FetchAll().Where(x => x.RoleId == get_manager.Role).Single();
            var get_check_last2 = new TblCheckManagerController().FetchAll().Where(x => x.ManagerId == id).Last();
    %>
    <%
            if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour <= 12)
            {
    %>
    <audio class="voice" src="../../Content/testdata/audio/Simasen.mp3" autoplay="1"></audio>
    <%}
            else
            {
                if (DateTime.Now.Hour >= 13 && DateTime.Now.Hour <= 16)
                { %>
    <audio class="voice" src="../../Content/testdata/audio/Simasen.mp3" autoplay="1"></audio>
    <%}
                else
                {
                    if (DateTime.Now.Hour >= 17 && DateTime.Now.Hour <= 22)
                    {
    %>
    <audio class="voice" src="../../Content/testdata/audio/Simasen.mp3" autoplay="1"></audio>
    <%
                        }
                    }
            }%>
    <tr class="error">
        <td colspan="4" class="w3-center w3-text-deep-orange"><i class="fa fa-frown-o"></i>&nbsp;<b>Đã xin vắng</b></td>
    </tr>
    <tr id="<%=get_check_last2.Id%>" class="<%=get_manager.ManagerId%>">
        <td class="checkinout-img w3-hide-small w3-center">
            <span class="check_id w3-hide"><%=get_check_last2.Id%></span>
            <img src="../Content/avatar/<%=get_manager.Avatar%>" class="w3-circle" alt="Avatar" />
        </td>
        <td>
            <span><%=get_manager.FullName %></span><br />
            <span class="w3-text-grey w3-hide-small"><%=get_role.RoleName %></span>
        </td>
        <td><%=work_time%></td>
        <%int get_id = int.Parse(Session["admin_id"].ToString());
          var check_cap = new TblManagerController().FetchAll().Where(x => x.ManagerId == get_id).Single();
          if (check_cap.Captain == true)
          { %>
        <td>
            <%if (get_check_last2.Accept == false)
              {
                  if (get_check_last2.CheckOut != null)
                  {%>
            <i title="Xác nhận" class="btn_confirm_check checkinout-option-btn fa fa-check w3-hover-text-teal"></i><%}
                  else
                  {%><%}
              }
              else
              { %>
            <i title="Đã xác nhận" class="checkinout-option-btn fa fa-check w3-text-teal"></i>
            <%} %>
            <i title="Chỉnh sửa" class="btn_edit_check checkinout-option-btn fa fa-wrench w3-hover-text-teal"></i>
            <i title="Xóa" class="btn_del_check checkinout-option-btn fa fa-trash w3-hover-text-teal"></i>
        </td>
        <%}
          else
          {
              if (get_check_last2.Accept == true)
              {
        %>

        <td>
            <i title="Đã xác nhận" class="checkinout-option-btn fa fa-check w3-text-teal"></i>
        </td>
        <%
              }
          } %>
    </tr>
    <%}%>
</body>
</html>
